#!/usr/bin/env python
#
# This script counts the state changes that occur in the same time.
#

from __future__ import with_statement
from sys import argv, exit

UP = 1
LOGIN = 2
LOGOUT = 3
DOWN = 4

if __name__ == '__main__':
    
    if len(argv) != 2:
        print 'Error! Usage: <LCC trace file>'
        exit(1)

    file_name = argv[1]

    with open(file_name, 'r') as h:
        events = [tuple(map(int, l.strip().split())) for l in h.readlines()]

    ltt = None
    lstate = None
    from_states = {}
    for tt, state in events:
        if ltt and tt == ltt:
            to_states = from_states.get(lstate, {})
            counter = to_states.get(state, 0)
            counter += 1

            to_states[state] = counter
            from_states[lstate] = to_states
        ltt = tt
        lstate = state
    
    for from_state in from_states:
        for to_state, counter in from_states[from_state].iteritems():
            print '%d\t%d\t%d' % (from_state, to_state, counter)
